package gw.com.android.presenter;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import io.reactivex.disposables.Disposable;

/**
 * 事件处理基类
 * Created by reeta.zou on 2016/12/16.
 */
public abstract class BasePresenter {

    /**添加等待框提示 */
    public Disposable rxBusRegister;
    public PresenterImpl mRequestImpl;
    public Activity mContext;

    protected Handler mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    };

    public void init(){
    }

    /**
     * 设置登录逻辑处理回调
     * @param loginImpl
     */
    public void setPresenterImpl(PresenterImpl loginImpl){
        mRequestImpl = loginImpl;
    }

    /**
     * 回收对象
     */
    public void clear(){
        if(null != mHandler){
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }
        mContext = null;
        if(null != rxBusRegister && !rxBusRegister.isDisposed()){
            rxBusRegister.dispose();
            rxBusRegister = null;
        }
    }

    /**
     *
     * @param bundle
     */
    protected void onResultPresenter(Bundle bundle){};

}
